package interactiond

import (
	"time"

	cinteractiond "gogs.xiaoyuanjijiehao.com/antlinker/antcms/core/interactiond"
	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/ddd"
)

// @collname 互动操作集合(i_interaction)
type collInteraction struct {
	InteractionID string    `bson:"_id" `
	IGID          string    `bson:"igid"`                 //互动组ID
	Code          string    `bson:"code"`                 //类型
	UID           string    `bson:"uid"`                  //互动用户
	Value         int       `bson:"value"`                //值
	Creator       string    `bson:"creator"`              //创建人
	CreTime       time.Time `bson:"creTime"`              //创建时间
	Status        int       `bson:"status"`               // 删除标识　-1 删除　0 正常
	DeleteTime    time.Time `bson:"deleteTime,omitempty"` //删除时间
	Deleter       string    `bson:"deleter,omitempty"`    //删除人

}

func (c collInteraction) CollID() string {
	return c.InteractionID
}
func (collInteraction) CollName() string {
	return collNameInteraction
}
func (c collInteraction) IsCache() bool {
	return c.InteractionID != "" && c.Status == 0
}

func (c collInteraction) CacheExpire() time.Duration {
	return 60 * time.Second
}
func (c *collInteraction) FullDesc(e cinteractiond.InteractionDesc) {
	c.IGID = e.IGID
	c.Code = e.Code
	c.UID = e.UID
	c.Value = e.Value

}
func (c collInteraction) ToDesc() cinteractiond.InteractionDesc {
	return cinteractiond.InteractionDesc{
		IGID:  c.IGID,
		Code:  c.Code,
		UID:   c.UID,
		Value: c.Value,
	}
}

func (c *collInteraction) FullOperator(e cinteractiond.Operator) {
	c.Creator = e.Creator
	c.CreTime = e.CreTime
	c.DeleteTime = e.DeleteTime
	c.Deleter = e.Deleter

}
func (c collInteraction) ToOperator() cinteractiond.Operator {
	return cinteractiond.Operator{
		Creator:    c.Creator,
		CreTime:    c.CreTime,
		DeleteTime: c.DeleteTime,
		Deleter:    c.Deleter,
	}
}

func (c collInteraction) ToAggregate() ddd.Aggregate {
	return c.ToInteractionAggregate()
}
func (c collInteraction) ToInteractionAggregate() *cinteractiond.InteractionAggregate {
	return &cinteractiond.InteractionAggregate{
		InteractionID:   c.InteractionID,
		InteractionDesc: c.ToDesc(),
		Operator:        c.ToOperator(),
	}
}
